package com.china08.yxyapi.rabbitmq.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.china08.yxyapi.config.RabbitConfig;
import com.china08.yxyapi.repository.mg.lecture.impl.YxyLecturePrePackRepositoryImpl;

/**
 * 备授课系统,pv统计,采纳了统计
 *
 */
@Component
@EnableRabbit
public class LectureStatisticListener {

    public static final Logger LOGGER = LoggerFactory.getLogger(LectureStatisticListener.class);

    @Autowired
    private YxyLecturePrePackRepositoryImpl yxyLecturePrePackRepositoryImpl;

    /**
     * @param message
     *            prepackId 备课包id
     */
    @RabbitListener(queues = RabbitConfig.YW_LECTURE_PREPACK_PV)
    private void lecturePvStatistics(String prepackId) {
        // rabbitMQ 2017.03.22
        // 获取id之后, 将pv数进行+1 操作
        yxyLecturePrePackRepositoryImpl.lecturePvPlus(prepackId);
        System.out.println("MQ: " + prepackId);
    }

    /**
     * @param message
     *            prepackId 备课包id
     */
    @RabbitListener(queues = RabbitConfig.YW_LECTURE_PREPACK_USED_COUNT)
    private void lecturesUsedStatistics(String prepackId) {
        // rabbitMQ 2017.03.22
        // 获取id之后, 将usedCount数进行+1 操作
        yxyLecturePrePackRepositoryImpl.lectureUsedPlus(prepackId);
        System.out.println("MQ: " + prepackId);
    }
}
